<template>
    <div class="wrap">
        <div class="main checkNum highRisk">
            <h3>
                <span class="checktit">安全检查</span>
                <span class="checktotal">隐患总数:{{listAllCount}}</span>
            </h3>
            <noData v-if="listAllCount == 0"></noData>
            <div class="bscroll">
                <vue-better-scroll class="wrapper"
                                   ref="scroll"
                                   :scrollbar="scrollbarObj"
                                   :pullDownRefresh="pullDownRefreshObj"
                                   :pullUpLoad="pullUpLoadObj"
                                   :startY="parseInt(startY)"
                                   @pullingDown="onPullingDown"
                                   @pullingUp="onPullingUp">
                    <div class="bscroll-container">
                        <div class="form-section broadcast">
                            <div class="form-item form-item-style1"
                                 v-for="(item,index) in listItems">
                                <div class="risktop">
                                    <div class="riskmsg">{{item.companyName}}</div>
                                    <div class="checkconBox">
                                        <div class="checkcon">{{item.checkType}}</div>
                                        <div class="riskdate">{{item.checkTime}}</div>
                                    </div>                                   
                                </div>
                                <div class="right-select"
                                        @click="toCheckDetail(item.id)">
                                    <i class="iconfont icon-jinru rightmsg"></i>
                                </div>
                            </div>
                            <!-- <div class="form-item form-item-style1">
                                <div class="risktop">
                                    <div class="riskmsg"></div>
                                    <div class="riskdate">2019-08-22</div>
                                </div>
                                <div class="right-select"
                                        @click="toWorkrisk">
                                    <i class="iconfont icon-jinru rightmsg"></i>
                                </div>
                            </div> -->
                        </div>
                    </div>
                </vue-better-scroll>
            </div>
        </div>
        <myMenu></myMenu>
    </div>
</template>

<script>
import VueBetterScroll from 'vue2-better-scroll'
import myMenu from '@/commonComponents/menu'
export default {
    data () {
        return {
            // dropDown: false
            // 这个配置可以开启滚动条，默认为 false。当设置为 true 或者是一个 Object 的时候，都会开启滚动条，默认是会 fade 的
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: {
                threshold: 90,
                stop: 40
            },
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            scrollToX: 0,
            scrollToY: 0,
            scrollToTime: 700,
            listItems: [
                {
                    id: 111,
                    companyName: '云南省质量技术监督综合技术检查验检基地云南省质量技术监督综合技术检查验检基地',
                    checkType: '（项目层级）专项检查',
                    checkTime: '2019-05-06'
                },
                {
                    id: 222,
                    companyName: '受限空间作业申请',
                    checkType: '（项目层级）日常检查',
                    checkTime: '2019-06-06'
                }
            ], // 列表集合
            listCount: 0, // 当前列表条数
            listAllCount: 2, // 总条数
            userInfo: {}
        }
    },
    components: {
        VueBetterScroll,
        myMenu
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
    },
    mounted () {
        // this.onPullingDown()
    },
    methods: {
        // 滚动到页面顶部
        scrollTo () {
            this.$refs.scroll.scrollTo(this.scrollToX, this.scrollToY, this.scrollToTime)
        },
        // 模拟数据请求
        getData () {
            let params = {
                'allowPaging': true,
                'business': 'FetchHiddenDangers',
                'data': {
                    'deptId': this.userInfo.deptid,
                    'state': '待完善'
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': '',
                'userId': this.userInfo.userid
            }
            return this.$axiosAjax.getConfigJson(params)
        },
        onPullingDown () {
            // 模拟下拉刷新
            this.$vux.loading.show({
                text: '加载中...'
            })
            this.listCount = 0
            this.getData().then(res => {
                if (res.data.code === 0) {
                    this.listItems = res.data.data
                    this.listCount = this.listItems.length
                    this.listAllCount = res.data.count
                }
                if (this.listCount < this.listAllCount) {
                    this.$refs.scroll.forceUpdate(true)
                } else {
                    this.$refs.scroll.forceUpdate(false)
                }
            }).finally(() => {
                this.$vux.loading.hide()
            })
        },
        onPullingUp () {
            // 模拟上拉 加载更多数据
            this.getData().then(res => {
                if (res.data.code === 0) {
                    this.listItems = this.listItems.concat(res.data.data)
                    this.listCount = this.listItems.length
                }
                if (this.listCount < this.listAllCount) {
                    this.$refs.scroll.forceUpdate(true)
                } else {
                    this.$refs.scroll.forceUpdate(false)
                }
            })
        },
        toCheckDetail(id) {

        }
    }
}
</script>

<style scoped>
.form-item-style1{
    height: 80px;
}
.wrap {
    background: #ebeef2;
    min-height: 20px;
}
.main {
    position: absolute;
    top: 5px;
    bottom: 0;
    width: 100%;
    border-radius: 16px 16px 0 0;
    background: #fff;
    padding-left: 20px;
}
.main h3 {
    display: flex;
    display: -webkit-flex;
    justify-content: space-between;
    height: 55px;
    line-height: 55px;
    padding-right: 20px;
    border-bottom: 1px solid #efeff4;
    font-size: 14px;
}
.bscroll {
    position: absolute;
    top: 65px;
    bottom: 0;
    left: 20px;
    right: 0;
    overflow: hidden;
}
.bscroll-container li {
    border-bottom: 1px solid #efeff4;
    padding: 18px 20px 12px 0;
}
.bscroll-container li > a {
    display: block;
}
.drop-down {
    position: absolute;
    top: 40px;
    left: 0px;
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 0.8rem;
    color: #ccc;
}
.checkNum .checktit,.checkNum .checktotal{
    color: #2269ff;
}
.highRisk .right-select{
    display: flex;
    display: -webkit-flex;
    justify-content: flex-start;
    align-items: center;
}
.risktop{
    flex: 1;
    align-items: center;
}
.riskmsg{
    font-size: 14px;
    line-height: 20px;
    color: #333;
    vertical-align: middle;
}
.checkconBox{
    display: flex;
    display: -webkit-flex;
    line-height: 30px;
}
.checkcon{
    font-size: 14px;
    color: #999;
    margin-right: 40px;
}
.riskdate{
    font-size: 14px;
    
    color: #999;
}
</style>
<style>
.hide-correct .before-trigger canvas {
    width: 50px !important;
    height: 80px !important;
}
</style>
